using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQVW_QOSTEP
    {
        public DataRow Convert2QVW_QOSTEP(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQVW_QOSTEP(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QKAUF"] = " ".PadRight(9 ); 
         dwReturn["QPAUF"] = " ".PadRight(13 ); 
         dwReturn["HRSTAFF"] = " ".PadRight(8 ); 
         dwReturn["QXDATE"] = " ".PadRight(0 ); 
         dwReturn["QXYEAR"] = " ".PadRight(4 ); 
         dwReturn["QXMONTH"] = " ".PadRight(2 ); 
         dwReturn["QXDAY"] = " ".PadRight(2 ); 
         dwReturn["QXQUARTER"] = " ".PadRight(41 ); 
         dwReturn["QEDATE"] = " ".PadRight(0 ); 
         dwReturn["QEYEAR"] = " ".PadRight(4 ); 
         dwReturn["QEMONTH"] = " ".PadRight(2 ); 
         dwReturn["QEDAY"] = " ".PadRight(2 ); 
         dwReturn["QEQUARTER"] = " ".PadRight(41 ); 
         dwReturn["QPLAN"] = " ".PadRight(8 ); 
         dwReturn["MERKM"] = " ".PadRight(4 ); 
         dwReturn["QOEPGROE"] = " ".PadRight(2 ); 
         dwReturn["QOEPGRKZ"] = " ".PadRight(2 ); 
         dwReturn["QMEEH"] = " ".PadRight(3 ); 
         dwReturn["QOENSWERT"] = " ".PadRight(0 ); 
         dwReturn["QOEMWERT"] = " ".PadRight(0 ); 
         dwReturn["RESULT"] = " ".PadRight(1 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQVW_QOSTEP(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_QOSTEP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQVW_QOSTEP(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQVW_QOSTEP(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQVW_QOSTEP(dwLocal, ITXDBVERSION);
            }
            UpdateQVW_QOSTEP(dwLocal);
        }
        public void InsertQVW_QOSTEP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QVW_QOSTEP(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_QOSTEP(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QVW_QOSTEP WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QVW_QOSTEP  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_QOSTEP";
            Return = Result;
            return Return;
        }
        public void DeleteQVW_QOSTEP(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_QOSTEP   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQVW_QOSTEP(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QVW_QOSTEP SET "
                    +"QKAUF= :QKAUF,"
                    +"QPAUF= :QPAUF,"
                    +"HRSTAFF= :HRSTAFF,"
                    +"QXDATE= :QXDATE,"
                    +"QXYEAR= :QXYEAR,"
                    +"QXMONTH= :QXMONTH,"
                    +"QXDAY= :QXDAY,"
                    +"QXQUARTER= :QXQUARTER,"
                    +"QEDATE= :QEDATE,"
                    +"QEYEAR= :QEYEAR,"
                    +"QEMONTH= :QEMONTH,"
                    +"QEDAY= :QEDAY,"
                    +"QEQUARTER= :QEQUARTER,"
                    +"QPLAN= :QPLAN,"
                    +"MERKM= :MERKM,"
                    +"QOEPGROE= :QOEPGROE,"
                    +"QOEPGRKZ= :QOEPGRKZ,"
                    +"QMEEH= :QMEEH,"
                    +"QOENSWERT= :QOENSWERT,"
                    +"QOEMWERT= :QOEMWERT,"
                    +"RESULT= :RESULT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QKAUF", OracleType.NVarChar).Value = dwData["QKAUF"].ToString(); 
          or1.Parameters.Add("QPAUF", OracleType.NVarChar).Value = dwData["QPAUF"].ToString(); 
          or1.Parameters.Add("HRSTAFF", OracleType.NVarChar).Value = dwData["HRSTAFF"].ToString(); 
          or1.Parameters.Add("QXDATE", OracleType.NVarChar).Value = dwData["QXDATE"].ToString(); 
          or1.Parameters.Add("QXYEAR", OracleType.NVarChar).Value = dwData["QXYEAR"].ToString(); 
          or1.Parameters.Add("QXMONTH", OracleType.NVarChar).Value = dwData["QXMONTH"].ToString(); 
          or1.Parameters.Add("QXDAY", OracleType.NVarChar).Value = dwData["QXDAY"].ToString(); 
          or1.Parameters.Add("QXQUARTER", OracleType.NVarChar).Value = dwData["QXQUARTER"].ToString(); 
          or1.Parameters.Add("QEDATE", OracleType.NVarChar).Value = dwData["QEDATE"].ToString(); 
          or1.Parameters.Add("QEYEAR", OracleType.NVarChar).Value = dwData["QEYEAR"].ToString(); 
          or1.Parameters.Add("QEMONTH", OracleType.NVarChar).Value = dwData["QEMONTH"].ToString(); 
          or1.Parameters.Add("QEDAY", OracleType.NVarChar).Value = dwData["QEDAY"].ToString(); 
          or1.Parameters.Add("QEQUARTER", OracleType.NVarChar).Value = dwData["QEQUARTER"].ToString(); 
          or1.Parameters.Add("QPLAN", OracleType.NVarChar).Value = dwData["QPLAN"].ToString(); 
          or1.Parameters.Add("MERKM", OracleType.NVarChar).Value = dwData["MERKM"].ToString(); 
          or1.Parameters.Add("QOEPGROE", OracleType.NVarChar).Value = dwData["QOEPGROE"].ToString(); 
          or1.Parameters.Add("QOEPGRKZ", OracleType.NVarChar).Value = dwData["QOEPGRKZ"].ToString(); 
          or1.Parameters.Add("QMEEH", OracleType.NVarChar).Value = dwData["QMEEH"].ToString(); 
          or1.Parameters.Add("QOENSWERT", OracleType.NVarChar).Value = dwData["QOENSWERT"].ToString(); 
          or1.Parameters.Add("QOEMWERT", OracleType.NVarChar).Value = dwData["QOEMWERT"].ToString(); 
          or1.Parameters.Add("RESULT", OracleType.NVarChar).Value = dwData["RESULT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
